<script setup lang="ts">
import { ref, watchEffect } from 'vue'
import { RouterLink, RouterView } from 'vue-router'
import { useThemeStore } from '@/stores/darkTheme'
useThemeStore().initTheme()

const isDark = ref(useThemeStore().isDark)

const toggleDarkMode = () => {
  useThemeStore().toggleDarkMode()
  isDark.value = useThemeStore().isDark
}
</script>

<template>
  <div
    class="tw-absolute tw-right-12 tw-top-8 tw-w-6 tw-h-6 tw-z-50 tw-cursor-pointer"
    @click="toggleDarkMode"
  >
    <!-- 图标：根据模式切换太阳/月亮 -->
    <i class="fas fa-sun tw-inline-block dark:tw-hidden text-yellow-500"></i>
    <i class="fas fa-moon tw-hidden dark:tw-inline-block text-blue-300"></i>
    <!-- <span class="tw-hidden dark:tw-block">🌞</span> -->
    <!-- <span class="tw-block dark:tw-hidden">🌙</span> -->
  </div>
  <div class="tw-fixed buttton-box tw-w-full tw-flex tw-place-items-center">
    <button
      @click="toggleDarkMode"
      class="tw-fixed tw-top-4 tw-left-4 tw-z-50 tw-p-2 tw-rounded-full tw-bg-gray-200 dark:tw-bg-gray-700 tw-transition-colors"
      aria-label="切换暗黑模式"
    >
      切换暗黑模式
    </button>
  </div>
  <div
    class="tw-w-full tw-transition-colors tw-duration-300 tw-flex tw-place-items-center tw-justify-center"
  >
    <!-- 示例：按钮在深色模式下变色 -->
    <button
      class="tw-p-4 tw-rounded tw-bg-primary dark:tw-bg-dark-primary tw-text-white tw-transition-colors"
      @click="toggleDarkMode"
    >
      测试按钮
    </button>
  </div>
  <RouterView />
</template>

<style>
header {
  line-height: 1.5;
  max-height: 100vh;
}

.logo {
  display: block;
  margin: 0 auto 2rem;
}

nav {
  width: 100%;
  font-size: 12px;
  text-align: center;
  margin-top: 2rem;
}

nav a.router-link-exact-active {
  color: var(--color-text);
}

nav a.router-link-exact-active:hover {
  background-color: transparent;
}

nav a {
  display: inline-block;
  padding: 0 1rem;
  border-left: 1px solid var(--color-border);
}

nav a:first-of-type {
  border: 0;
}

@media (min-width: 1024px) {
  header {
    display: flex;
    place-items: center;
    padding-right: calc(var(--section-gap) / 2);
  }

  .logo {
    margin: 0 2rem 0 0;
  }

  header .wrapper {
    display: flex;
    place-items: flex-start;
    flex-wrap: wrap;
  }

  nav {
    text-align: left;
    margin-left: -1rem;
    font-size: 1rem;

    padding: 1rem 0;
    margin-top: 1rem;
  }
}
</style>
